package com.nj.liandi.gulimall.search.controller;

import com.nj.liandi.common.exception.BizeCodeEnume;
import com.nj.liandi.common.to.es.SkuEsModel;
import com.nj.liandi.common.utils.R;
import com.nj.liandi.gulimall.search.service.ProductSaveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RequestMapping("/search/save")
@RestController
public class ElasticSaveController {
    private static Logger logger = LoggerFactory.getLogger(ElasticSaveController.class);
    @Autowired
    ProductSaveService productSaveService;


    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels){
        Boolean b =false;
        try {
            b = productSaveService.productStatusUp(skuEsModels);
        } catch (IOException e) {
            logger.error("商品上架出现异常,原因是:{}",e);
            return R.error(BizeCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizeCodeEnume.PRODUCT_UP_EXCEPTION.getMessage());
        }
        if (b) {
            return R.ok();
        }else {
            return R.error(BizeCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizeCodeEnume.PRODUCT_UP_EXCEPTION.getMessage());
        }

    }

}
